unit GMedStoris;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, GForm, cxGraphics, cxPropertiesStore, dxBarExtItems, dxBar,
  cxClasses, ActnList, dxStatusBar, cxControls, cxPC, cxStyles, cxCustomData,
  cxFilter, cxData, cxDataStorage, cxEdit, DB, cxDBData, cxGridLevel,
  cxGridCustomTableView, cxGridTableView, cxGridDBTableView, cxGridCustomView,
  cxGrid, cxNavigator, cxDBNavigator, cxContainer, cxGroupBox, cxCalc, impexp,
  cxLookAndFeelPainters;

type
  TfMedStoris = class(TGamaForm)
    tsSarasas: TcxTabSheet;
    dbgSarasas: TcxGrid;
    dbgSarasasDBTableView: TcxGridDBTableView;
    dbgSarasasLevel1: TcxGridLevel;
    dbgSarasasDBTableViewstoris: TcxGridDBColumn;
    cxGroupBox1: TcxGroupBox;
    dbnNav: TcxDBNavigator;
    procedure FormShow(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure GmiImportasClick(Sender: TObject);
  private
    { Private declarations }
    m_arImportas: boolean;

    procedure LentelesOn;
    procedure LentelesOff;
    //
    procedure MainBeforeInserOrEdit(DataSet: TDataSet);
    procedure MainBeforePost(DataSet: TDataSet);
    procedure MainAfterPostOrDelete(DataSet: TDataSet);
    procedure MainAfterPostOrDeleteOrCancel(DataSet: TDataSet);
    procedure MainPostError(DataSet: TDataSet;
                E: EDatabaseError; var Action: TDataAction);
    procedure MainNewRecord(DataSet: TDataSet);
  public
    { Public declarations }
    procedure RefreshTables; override;
  end;

var
  fMedStoris: TfMedStoris;

implementation

{$R *.dfm}

uses
  bendri, med_dm, Tools;

procedure TfMedStoris.LentelesOn;
begin
  with dmMed do begin
    tbMedStoris.BeforeInsert  := self.MainBeforeInserOrEdit;
    tbMedStoris.BeforeEdit    := self.MainBeforeInserOrEdit;
    tbMedStoris.BeforePost    := self.MainBeforePost;
    tbMedStoris.AfterPost     := self.MainAfterPostOrDelete;
    tbMedStoris.AfterDelete   := self.MainAfterPostOrDelete;
    tbMedStoris.AfterCancel   := self.MainAfterPostOrDeleteOrCancel;
    //tbMedRastKub.OnPostError   := self.MainPostError;
    tbMedStoris.OnNewRecord   := self.MainNewRecord;
  end;
end;

procedure TfMedStoris.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  inherited;
  LentelesOff;
end;

procedure TfMedStoris.FormShow(Sender: TObject);
begin
  inherited;
  LentelesOn;
end;

procedure TfMedStoris.GmiImportasClick(Sender: TObject);
begin
  try
    LentelesOff;
    m_arImportas := true;
    fImpExp.DataSet := dmMed.tbMedStoris;
    dmMed.tbMedStoris.DisableControls;
    //fImpExp.BeforeStart := ImportBeforeStart;
    //fImpExp.AfterEnd := ImportAfterEnd;
    //dmVagonai.tbVStotys.OnNewRecord := self.StotysNewRecord;
    //fImpExp.BeforeInsert := ImportBeforeInsert;
    fImpExp.ImEx := importas;
    fImpExp.IniFileName := 'ismatavimai.ini';
    if fImpExp.ShowModal(DokTipas) <> mrYes then Exit;
  finally
    m_arImportas := false;
    dmBendras.ApplyUpdatesAfterPostOrDelete( dmMed.tbMedStoris );
    dmMed.tbMedStoris.Refresh;
    dmMed.tbMedStoris.EnableControls;
    bRefreshTables := true;
    //dmVagonai.tbVVagonaiS.Refresh;
    LentelesOn;
  end;
end;

procedure TfMedStoris.LentelesOff;
begin
  with dmMed do begin
    tbMedStoris.BeforeInsert  := nil;
    tbMedStoris.BeforeEdit    := nil;
    tbMedStoris.BeforePost    := nil;
    tbMedStoris.AfterPost     := nil;
    tbMedStoris.AfterDelete   := nil;
    tbMedStoris.AfterCancel   := nil;
    //tbMedRastKub.OnPostError   := nil;
    tbMedStoris.OnNewRecord   := nil;
  end;
end;

procedure TfMedStoris.MainBeforePost(DataSet: TDataSet);
begin
  //MessageText := '';
  //dmBendras.RandomIDBeforePost(DataSet);
end;

procedure TfMedStoris.MainPostError(DataSet: TDataSet;
                E: EDatabaseError; var Action: TDataAction);
begin
  //dmBendras.RandomIDPostError(DataSet, E, Action);
end;

procedure TfMedStoris.MainNewRecord(DataSet: TDataSet);
begin
  //
end;

procedure TfMedStoris.MainAfterPostOrDelete(DataSet: TDataSet);
begin
  dmBendras.ApplyUpdatesAfterPostOrDelete(DataSet);
  MainAfterPostOrDeleteOrCancel(DataSet);
  bRefreshTables := true;
end;

procedure TfMedStoris.MainAfterPostOrDeleteOrCancel(DataSet: TDataSet);
begin
  SetControlsEditColor( DataSet, GamaPageControl, false );
end;

procedure TfMedStoris.MainBeforeInserOrEdit(DataSet: TDataSet);
begin
  SetControlsEditColor( DataSet, GamaPageControl, true);
end;

procedure TfMedStoris.RefreshTables;
begin
  if bRefreshTables then begin
    bRefreshTables := false;
    //dmAlga.tbIssilavLookup.Refresh;
  end
end;

end.
